# models/sys_user_passwords.py
from sqlalchemy import Column, String, DateTime, Boolean, Integer, BIGINT, TEXT
from src.core.ormdb import Base
from src.core import str_utils as strU


class SysUserPasswords(Base):
    __tablename__ = "sys_user_passwords"
    __table_args__ = {'comment': '用户密码表（仅凭证类型需要密码时存记录）'}  # 表的注释

    # 主键
    id = Column(String(36), primary_key=True, default=lambda: strU.generate_id(), comment="密码记录唯一标识ID")

    # 关联到用户主表
    user_id = Column(String(36), nullable=False, unique=True, comment="用户ID，关联 sys_user.id")

    # 密码哈希与盐
    password_hash = Column(String(255), nullable=False, comment="密码哈希（bcrypt/argon2）")
    salt = Column(String(50), nullable=True, comment="盐值（如使用bcrypt可空）")

    # 密码策略字段
    must_change = Column(Boolean, default=False, comment="下次登录是否必须修改密码")
    changed_at = Column(DateTime, nullable=True, comment="最近一次修改密码时间")
    expire_at = Column(DateTime, nullable=True, comment="密码过期时间（可选）")
    # 审计字段
    create_date = Column(DateTime, default=lambda: strU.now(), comment="创建时间")
    creator_by = Column(String(255), nullable=True, comment="创建者")
    last_updated_date = Column(DateTime, nullable=True, onupdate=lambda: strU.now(), comment="最后更新时间")
    last_updated_by = Column(String(255), nullable=True, comment="最后更新者")
    # 软删除
    deletion_mark = Column(Boolean, default=False, comment="删除标志：0未删除，1已删除")
    deletion_date = Column(DateTime, nullable=True, comment="删除时间")
    deletion_by = Column(String(255), nullable=True, comment="删除者")
